#include "uti_interface.h"
using namespace std;


//
//BarSerInfo barserinfo;
//
//strcpy(barserinfo.barinfo.instru, m_pthreadcfg->drivebararr[i].instru);
//barserinfo.barinfo.type = Bartype::tick;
//barserinfo.barinfo.cnt = 1;
//barserinfo.sersize = 3600;
//barserinfo.p = pticksercallback_fun[i];
//
//bool GetBarSeries(const char* ins, Bartype type, unsigned int cnt, 
//					unsigned int agonum, BarSeries** ppbarser/*out*/)
//{
//
//}


bool EnableGlobalPrivilege()
{
	HANDLE	hToken	= NULL;
	if(!OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,&hToken))
	{
		printf("[EnableGlobalPrivilege] OpenProcessToken error: %u\n", GetLastError() ); 

	}



	TOKEN_PRIVILEGES tp;
	LUID luid;

	if ( !LookupPrivilegeValue( 
		NULL,            // lookup privilege on local system
		"SeCreateGlobalPrivilege",   // privilege to lookup 
		&luid ) )        // receives LUID of privilege
	{
		printf("[EnableGlobalPrivilege] LookupPrivilegeValue error: %u\n", GetLastError() ); 
		return FALSE; 
	}

	tp.PrivilegeCount = 1;
	tp.Privileges[0].Luid = luid;
	tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;


	// Enable the privilege or disable all privileges.

	if ( !AdjustTokenPrivileges(
		hToken, 
		FALSE, 
		&tp, 
		sizeof(TOKEN_PRIVILEGES), 
		(PTOKEN_PRIVILEGES) NULL, 
		(PDWORD) NULL) )
	{ 
		printf("[EnableGlobalPrivilege] AdjustTokenPrivileges error: %u\n", GetLastError() ); 
		return FALSE; 
	} 

	if (GetLastError() == ERROR_NOT_ALL_ASSIGNED)
	{
		printf("[EnableGlobalPrivilege] The token does not have the specified privilege. \n");
		//return FALSE;
	} 

	if (GetLastError() == ERROR_SUCCESS)
	{
		printf("[EnableGlobalPrivilege] The token does not have the specified privilege. \n");
		//return FALSE;
	} 


	if (hToken)
		CloseHandle(hToken);


	return TRUE;

}
//
//bool GetBarSeries(BarSerInfo* pserinfo, unsigned int agonum, BarSeries** ppbarser/*out*/)
//{
//
//	*ppbarser = new BarSeries(pserinfo);
//	if (NULL == *ppbarser)
//	{
//		cerr<<"[GetBarSeries] Not enough memory for user bar series"<<endl;	
//		return false;
//	}
//
//	////////////////////////////
//	//use *ppbarser to read file at least agonum bar
//
//	return true;
//}
//
//bool GetOrderSeries(OrderSerInfo* pserinfo, OrderSeries** pporderser/*out*/)//no need to read from file, so need for agonum
//{
//
//	*pporderser = new OrderSeries(pserinfo);
//
//	if (NULL == *pporderser)
//	{
//		cerr<<"[GetOrderSeries] Not enough memory for user order series"<<endl;	
//		return false;
//	}
//
//
//	return true;
//}
//
//bool GetOrderSeries(unsigned int sersize, void (*pcallback_fun)(), OrderSeries** pporderser/*out*/)//no need to read from file, so need for agonum
//{
//	OrderSerInfo orderserinfo;
//
//	orderserinfo.sersize = sersize;
//	orderserinfo.p = pcallback_fun;
//
//	*pporderser = new OrderSeries(&orderserinfo);
//
//	if (NULL == *pporderser)
//	{
//		cerr<<"[GetOrderSeries] Not enough memory for user order series"<<endl;	
//		return false;
//	}
//
//
//	return true;
//}
//
//
//bool GetTradeSeries(TradeSerInfo* pserinfo, TradeSeries** pptradeser/*out*/)//no need to read from file, so need for agonum
//{
//
//	*pptradeser = new TradeSeries(pserinfo);
//
//	if (NULL == *pptradeser)
//	{
//		cerr<<"[GetTradeSeries] Not enough memory for user trade series"<<endl;	
//		return false;
//	}
//	return true;
//}
//
//
//
//bool GetTradeSeries(unsigned int sersize, void (*pcallback_fun)(), TradeSeries** pptradeser/*out*/)//no need to read from file, so need for agonum
//{
//	TradeSerInfo tradeserinfo;
//
//	tradeserinfo.sersize = sersize;
//	tradeserinfo.p = pcallback_fun;
//
//	*pptradeser = new TradeSeries(&tradeserinfo);
//
//	if (NULL == *pptradeser)
//	{
//		cerr<<"[GetTradeSeries] Not enough memory for user trade series"<<endl;	
//		return false;
//	}
//	return true;
//}
//


//
//bool GetMapSeries(TdMapSerInfo* pserinfo, OrderSysMapSeries** ppmapser/*out*/)
//{
//	*ppmapser = new OrderSysMapSeries(pserinfo);
//
//	if (NULL == *ppmapser)
//	{
//		cerr<<"[GetMapSeries] Not enough memory for map series"<<endl;	
//		return false;
//	}
//	return true;
//}
//
//
//bool GetIndexSeries(IndexSerInfo* pserinfo, IndexSeries** ppindexser/*out*/)
//{
//	*ppindexser = new IndexSeries(pserinfo);
//
//	if (NULL == *ppindexser)
//	{
//		cerr<<"[GetIndexSeries] Not enough memory for index series"<<endl;	
//		return false;
//	}
//	return true;
//}
//
//
//
//bool GetIndexSeries(unsigned int sersize, void (*pcallback_fun)(), IndexSeries** ppindexser/*out*/)
//{
//	IndexSerInfo indexserinfo;
//
//	indexserinfo.sersize = sersize;
//	indexserinfo.p = pcallback_fun;
//
//	*ppindexser = new IndexSeries(&indexserinfo);
//
//	if (NULL == *ppindexser)
//	{
//		cerr<<"[GetIndexSeries] Not enough memory for index series"<<endl;	
//		return false;
//	}
//	return true;
//}
